package poo.heapgui;

import java.io.IOException;
import java.util.Iterator;

import poo.agendina.Agendina;
import poo.agendina.Nominativo;
import poo.indice.Parola;

public abstract class HeapAstratto implements Heap {

	@Override
	public int size() {
		int c = 0;
		for (Iterator<String> it = this.iterator(); it.hasNext(); it.next(), c++)
			;
		return c;
	}

	@Override
	public void svuota() {
		Iterator<String> it = iterator();
		while (it.hasNext()) {
			it.next();
			it.remove();
		}
	}

	@Override
	public void Aggiungi(String s) {
		// da implementare nelle classi eredi, almeno per ora

	}

	@Override
	public void Rimuovi(String s) {
		Iterator<String> it = iterator();
		while (it.hasNext()) {
			String tmp = it.next();
			if (tmp.equals(s)) {
				it.remove();
			}
			if (tmp.compareTo(s) > 0)
				return;
		}
	}

	@Override
	public String cerca(String s) {
		Iterator<String> it = iterator();
		while (it.hasNext()) {
			String tmp = it.next();
			if (tmp.equals(s))
				return s;
			if (tmp.compareTo(s) > 0)
				return null;
		}

		return null;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder(200);
		for (String n : this) {
			sb.append(n);
			sb.append("\n");
		}
		return sb.toString();
	}// to String

	public boolean equals(Object x) {
		if (!(x instanceof Heap))
			return false;
		if (x == this)
			return true;
		Heap a = (Heap) x;
		if (size() != a.size())
			return false;
		Iterator<String> it1 = this.iterator();
		Iterator<String> it2 = a.iterator();
		while (it1.hasNext()) {
			String x1 = it1.next(), x2 = it2.next();
			if (!x1.equals(x2))
				return false;
		}
		return true;
	}// equals

	public int hashCode() {
		final int MULT = 83;
		int h = 0;
		for (String n : this)
			h = h * MULT + n.hashCode();
		return h;
	}// hashCode

	@Override
	public void salva(String nomeFile) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void carica(String nomeFile) throws IOException {
		// TODO Auto-generated method stub

	}

}
